package com.roncoo.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.roncoo.video.entity.UserCourse;
import com.roncoo.video.dao.UserCourseMapper;
import com.roncoo.video.service.UserCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wdf
 * @since 2021-04-10
 */
@Service
public class UserCourseServiceImpl extends ServiceImpl<UserCourseMapper, UserCourse> implements UserCourseService {


    /**
     * 添加学习记录
     * @param userCourse
     * @return
     */
    @Override
    public boolean addData(UserCourse userCourse) {
        QueryWrapper<UserCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userCourse.getUserId());
        queryWrapper.eq("course_id",userCourse.getCourseId());
        //获取当前时间
        Date date = new Date();
        //设置要获取到什么样的时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //获取String类型的时间
        String createdate = sdf.format(date);
        userCourse.setGmtCreate(createdate);
        boolean update = this.update(userCourse, queryWrapper);
        return update;
    }
}
